﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Polaris.Common.FilterAttribute;
using Polaris.Domain.Interfaces.Admin;
using Polaris.Domain.Model.Dto.Said.Request;

namespace Polaris.WebApi.Controllers.Admin
{
    /// <summary>
    /// 说说接口控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SaidController : BaseController
    {
        private readonly ISaid _said;
        public SaidController(ISaid said)
        {
            _said = said;
        }

        /// <summary>
        /// 创建说说
        /// </summary>
        /// <param name="create"></param>
        /// <returns></returns>
        [HttpPost]
        [CustomAuthorize(IsAuthorize = true)]
        public async Task<IActionResult> CreateSaid(CreateSaidRequest create)
        {
            var userId = HttpContext.GetUserId();
            await _said.CreateSaid(create, Guid.Parse(userId));
            return SUCCESS("添加成功");
        }

        /// <summary>
        /// 删除说说
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        [CustomAuthorize(IsAuthorize = true)]
        public async Task<IActionResult> DeleteSaid(string id)
        {
            var userId = HttpContext.GetUserId();
            await _said.DeleteSaid(id, Guid.Parse(userId));
            return SUCCESS("删除成功");
        }

        /// <summary>
        /// 修改说说
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        [HttpPost]
        [CustomAuthorize(IsAuthorize = true)]
        public async Task<IActionResult> UpdateSaid(SaidInfoResponse update)
        {
            var userId = HttpContext.GetUserId();
            await _said.UpdateSaid(update, Guid.Parse(userId));
            return SUCCESS("修改成功");
        }

        /// <summary>
        /// 获取说说列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        [CustomAuthorize(IsAuthorize = true)]
        public async Task<IActionResult> GetSaidList(SaidQueryRequest query)
        {
            var userId = HttpContext.GetUserId();
            var result = await _said.GetSaidList(query);
            return SUCCESS(result);
        }

        /// <summary>
        /// 根据id获取说说
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [CustomAuthorize(IsAuthorize = true)]
        public async Task<IActionResult> GetSaidById(string id)
        {
            var userId = HttpContext.GetUserId();
            var result = await _said.GetSaidById(id);
            return SUCCESS(result);
        }
    }
}
